package com.swotplus.system.sys.service.impl;

import com.swotplus.system.sys.entity.SysPost;
import com.swotplus.system.sys.mapper.SysPostMapper;
import com.swotplus.system.sys.service.SysPostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 岗位信息表 服务实现类
 * </p>
 *
 * @author hugang
 * @since 2020-04-12
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {
        @Autowired
        private SysPostMapper  sysPostMapper;

        /**
         * 根据用户ID查询岗位
         *
         * @param userId 用户ID
         * @return 岗位列表
         */
        @Override
        public List<SysPost> selectPostsByUserId(String userId) {
                List<SysPost> userPosts = sysPostMapper.selectPostsByUserId(userId);
                List<SysPost> posts = sysPostMapper.selectList(null);
                for (SysPost post : posts)
                {
                        for (SysPost sysPost : userPosts)
                        {
                                if (post.getId().equals(sysPost.getId()))
                                {
                                        post.setFlag(true);
                                        break;
                                }
                        }
                }
                return posts;
        }
}
